const { Order } = require('../models')

module.exports = {
  async submitOrder (req, res) {
    try {
      const order = await Order.create(req.body)
      res.send(order.toJSON())
    } catch (err) {
      res.status(400).send({
        error: 'Order submit error'
      })
    }
  },
  async getOrdersByCondition (req, res) {
    try {
      // const {province, city, area, bedroom, livingroom, kitchen, balcony, bathroom, sqm, phone} = req.body;
      const orders = await Order.findAll({
        where: req.body
      })

      res.send(orders)
    } catch (err) {
      res.status(400).send({
        error: 'Order query error'
      })
    }
  }
}
